1844C - Particles - CodeForces Solution


constructive algorithms greedy implementation math

Please click on ads to support us..

C++ Code:

/*
    || धर्मं चर। धर्मान्न प्रमदितव्यम् ||
*/

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;

using ll = long long;
using ld = long double;
const ld Pi = 3.141592653589793238462643;
const ld e = 2.718281828459045235360;
const ll MOD = 100;

#define f(variable,s,e,j) for(ll variable = s ; variable < e ; variable+=j)
#define fr(variable,s,e,j) for(ll variable = s ; variable > e ; variable-=j)
#define test(n) while(n--)
#define trav(x,y) for(auto x : y)
#define endl '\n'

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mems(x,y) memset(x , y, sizeof(x));
#define pb(v) push_back(v);
#define pp pop_back();

#define MODadd(x,y) ((x % MOD) + (y % MOD) + MOD ) % MOD
#define MODsub(x,y) ((max(x,y) % MOD) - (min(x,y) % MOD) + MOD ) % MOD
#define MODmul(x,y) ((x % MOD) * (y % MOD)) % MOD

#ifndef vipplovve
#define debug(value) cerr << #value << " : " << value << endl;
#else
#define debug(value);
#endif

int main()
{
    #ifndef vipplovve
        freopen("errors.txt","w",stderr);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    auto beg = high_resolution_clock::now();

    //Code Here.

    ll t;

    cin >> t;

    test(t)
    {
        ll len;

        cin >> len;

        ll data[len];

        ll EveSum = 0, OddSum = 0;

        f(x,0,len,1)
        {
            cin >> data[x];

            if(data[x] > 0)
            {
                if(x&1)
                    OddSum += data[x];

                else
                    EveSum += data[x];
            }
        }

        if(!EveSum && !OddSum)
            cout << *max_element(data,data+len) << endl;

        else
            cout << max(EveSum,OddSum) << endl;
    }

    auto end = high_resolution_clock::now();

    auto duration = duration_cast <microseconds> (end - beg);
    
    #ifndef vipplovve
        cerr << endl << "Time Taken : " << duration.count() / 1000 << " ms." << endl;
    #endif

    return 0;
}


Comments

Submit
0 Comments
More Questions

1251B - Binary Palindromes
768B - Code For 1
363B - Fence
991B - Getting an A
246A - Buggy Sorting
884A - Book Reading
1180A - Alex and a Rhombus
445A - DZY Loves Chessboard
1372A - Omkar and Completion
159D - Palindrome pairs
981B - Businessmen Problems
1668A - Direction Change
1667B - Optimal Partition
1668B - Social Distance
88B - Keyboard
580B - Kefa and Company
960A - Check the string
1220A - Cards
897A - Scarborough Fair
1433B - Yet Another Bookshelf
1283B - Candies Division
1451B - Non-Substring Subsequence
1408B - Arrays Sum
1430A - Number of Apartments
1475A - Odd Divisor
1454B - Unique Bid Auction
978C - Letters
501B - Misha and Changing Handles
1496A - Split it
1666L - Labyrinth